/*
*作者---杨彬
*
*/
<template>
    <div>
    <cake-nav :navData="sData.myOrder.navText"></cake-nav>
    <empty-content :text="sData.emptyContent" v-if='isEmpty' class="emptyBox"></empty-content>
    
    <section class="order-content">
      <!--<div class="this-splace"></div>-->
      <!--<div class="order-item" v-for="(nitem,nindex) in defaultData">-->
        <!--<p class="item-title-warp">-->
          <!--<span class="orderNo-text" v-text="sData.myOrder.orderNumberCn"></span>-->
          <!--<span class="orderNo-number" v-text="nitem.id"></span>-->
          <!--<span class="order-type com-div-middle-ab" v-text="sData.myOrder.type[nitem.status].name"></span>-->
        <!--</p>-->
        <!--<div class="item-content-warp">-->
          <!--<img src="../../assets/index/ru2.png" v-for="mitem in nitem.img">-->
          <!--<div class="cn-text-warp">-->
            <!--<p class="product-title" v-text="nitem.title"></p>-->
            <!--<p class="product-detail" v-text=nitem.detail></p>-->
          <!--</div>-->
        <!--</div>-->
        <!--<div class="item-price">-->
          <!--<span class="money-cn" v-text="nitem.status==0?sData.myOrder.realPayCn[1]:sData.myOrder.realPayCn[0]"></span>-->
          <!--<span class="money-warp">￥<span v-text="nitem.money"></span></span>-->
        <!--</div>-->
        <!--<div class="item-operation" v-if="sData.myOrder.type[nitem.status].url.length>0">-->
          <!--<button type="button" v-text="sitem.text" @click=itemOperation(nitem.id,sitem.val)-->
                   <!--v-for="sitem in sData.myOrder.type[nitem.status].url"></button>-->
        <!--</div>-->
      <!--</div>-->

      <div class="order-item" v-for="(nitem,nindex) in orderListData" v-if="!nitem.orderItemBeans.length<1" >
        <p class="item-title-warp" >
          <span class="orderNo-text" v-text="sData.myOrder.orderNumberCn"></span>
          <span class="orderNo-number" v-text="nitem.sn"></span>
          <span class="order-type com-div-middle-ab" v-text="sData.myOrder.type[nitem.orderStatus].name"></span>
        </p>
        <div class="item-content-warp" @click="orderDetail(nitem)">
          <img :src="mitem.thumbnail" v-for="mitem in nitem.orderItemBeans" >
          <div class="cn-text-warp" v-if="nitem.orderItemBeans.length==1" v-for="mitem in nitem.orderItemBeans">
            <p class="product-title" v-text="mitem.name"></p>
            <p class="product-detail" v-text="mitem.intro" v-if="mitem.intro != 'undefined'?true:false"></p>
          </div>
        </div>
        <div class="item-price">
          <span class="money-cn" v-text="nitem.orderStatus==0?sData.myOrder.realPayCn[1]:sData.myOrder.realPayCn[0]"></span>
          <span class="money-warp">￥<span v-text="nitem.amountPaid"></span></span>
        </div>
        <div class="item-operation" v-if="sData.myOrder.type[nitem.orderStatus].url.length>0">
          <button type="button" v-text="sitem.text" @click="itemOperation(nitem,sitem.val)"
                  v-for="sitem in sData.myOrder.type[nitem.orderStatus].url"></button>
        </div>
      </div>

    </section>
    <div class="pop" v-show='cancelOrder'>
       <div>
           <p class='tit'>确认取消此订单吗?</p>
           <p class='btn'>
               <span class='cancel' @click = 'cancel'>取消</span>
               <span class='submit' @click = 'sure'>确认</span>
           </p>
       </div>
    </div>
    </div>
</template>
<script type="text/javascript">
  import cakeNav from "src/components/com/nav/nav.vue";
  import emptyContent from "src/components/com/emptyContent/emptyContent.vue";
  export  default {
    props:["sData"],
    components:{cakeNav,emptyContent},
    data(){
      return{
        defaultData:[
          // {status:"0",id:"232321111244",money:"1020",title:'草莓千层水果蛋糕',
          //   detail:'4寸/3套餐具/生日帽/巧克力牌:happy/数字蜡烛:20',img:[1]},
          // {status:"1",id:"232321111222",money:"1030",title:'5种口味手工曲奇',
          //   detail:'4寸/3套餐具/生日帽/巧克力牌:happy/数字蜡烛:20',img:[1,2]},
          // {status:"2",id:"232321111222",money:"1040",title:'草莓千层水果蛋糕',
          //   detail:'4寸/3套餐具/生日帽/巧克力牌:happy/数字蜡烛:20',img:[1]},
          // {status:"3",id:"232321111222",money:"1050",title:'草莓千层水果蛋糕',
          //   detail:'4寸/3套餐具/生日帽/巧克力牌:happy/数字蜡烛:20',img:[1,2]},
          // {status:"4",id:"232321111222",money:"1060",title:'草莓千层水果蛋糕',
          //   detail:'4寸/3套餐具/生日帽/巧克力牌:happy/数字蜡烛:20',img:[1,2]},
          // {status:"5",id:"232321111222",money:"1070",title:'草莓千层水果蛋糕',
          //   detail:'4寸/3套餐具/生日帽/巧克力牌:happy/数字蜡烛:20',img:[1,2]},
          // {status:"6",id:"232321111222",money:"1080",title:'草莓千层水果蛋糕',
          //   detail:'4寸/3套餐具/生日帽/巧克力牌:happy/数字蜡烛:20',img:[1,2]}
        ],
        orderListData:[],
        isEmpty:false,
        cancelOrder:false,
        currentOrder:''
      }
    },
    methods:{
      sure () {
        this.postAjax(this.sData.url.cancelOrderUrl,{ id:this.currentOrder.id},(res)=>{
            //取消成功再次获取数据
            if(res && res.message=='OK'){
              this.getData(this.$route.params.orderType);
            }else {}
          });
        this.cancelOrder = false;
      },
      cancel(){
        this.cancelOrder = false;
      },
      orderDetail(nitem){
          //跳转商品详情页
        window.location.href=(`#/orderDetail/${nitem.orderStatus}`);
        // this.m$y.sessionStores.set("orderData",nitem);
        m$.sessionStores.set("orderData",nitem)
      },
      
      itemOperation (orderData,operaionId) {
        //operaionId为  立即取消  按钮状态时执行
        console.log(operaionId);
        if(operaionId==0){
          this.cancelOrder = true;
          this.currentOrder = orderData; 
        }
        //operaionId为  再次购买  按钮状态时执行
        else if(operaionId==5){
          console.log("再次购买");
        }
        //operaionId为 查看物流  按钮状态时执行
        else if(operaionId==2){
          console.log("查看物流");
        }
        //operaionId为 确认收货  按钮状态时执行
        else if(operaionId==3){
          console.log("确认收货");
          this.currentOrder = orderData;
          this.postAjax(this.sData.url.sureReceive,{orderId:orderData.id},(res)=>{
                console.log(res);
                if(res && res.status==200){
                  //重新获取数据
                  m$.template({
                    val:'收货成功',
                    time:1200
                  })
                  //再次获得数据
                  var othis = this;
                  setTimeout(function(){
                    othis.getData(othis.$route.params.orderType);
                  },1000)
                }
            })
        }
        else if(operaionId==1){
         console.log("立即支付");
         if(Number(orderData.amountPaid)==0){
          this.postAjax(this.sData.url.payWeixin,{ orderId : orderData.id,amount : 0},(res)=>{
                if(res && res.message == 'OK' ){
                  m$.template({
                    val: '支付成功啦',
                    time: 1500
                  });
                  location.reload();
                }else {
                  m$.template({
                    val: '服务器开小差啦,请重试',
                    time: 1500
                  })
                }
              })
         }else{
          this.$router.replace('/goPay/'+orderData.id);
         }
          
        }
        else if(operaionId==4){
         console.log("立即评价");
         this.$router.replace('/evaluate/'+orderData.id);
        }
      },
      
      getData (orderStatus) {
        this.isEmpty=false;
        this.orderListData = [];
        this.getAjax(this.sData.url.findOrderByStatusUrl,{orderStatus : (parseInt(orderStatus)<0) ? "" : orderStatus,userId :this.sData.userId},(res)=>{
            console.log(res);
            if(res && res.message=='OK'){
              if(res.data.length!=0){
                  res.data.forEach((item)=>{
                    this.orderListData.push(item);
                  });
                  this.isEmpty = false;
              }else{
                this.isEmpty=true;
              }
              if(orderStatus == 4){//已发货和配送中同在
                this.getAjax(this.sData.url.findOrderByStatusUrl,{orderStatus :2,userId :this.sData.userId},(res)=>{
                    console.log(res);
                    if(res && res.message=='OK'){
                        if(res.data.length!=0){
                            res.data.forEach((item)=>{
                              this.orderListData.push(item);
                            });
                          console.log('订单数量')
                          if(this.orderListData.length == 0){
                            this.isEmpty=true;
                          }else{
                            this.isEmpty=false;
                          }
                        }
                    }
                }) 
              }
              
            }
        })
      }
    },
    created () {
      //console.log(this.orderListData)
      console.log(this.sData.myOrder.type[0].url)
      this.getData(this.$route.params.orderType);
      document.title=this.sData.myOrder.title;
    },
    watch : {
      '$route':function (val) {
        this.orderListData = [];
        this.getData(val.params.orderType)
      }
    },

  }
</script>
<style scoped lang="less">
    @import "orderList";
</style>
